import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_translator/app/modules/videoCall/controller/utils.dart';
import 'package:smart_translator/app/style/widget_style.dart';
import 'package:get/get.dart';
import 'package:smart_translator/app/widgets/CommonWidgets.dart';
import 'package:tencent_rtc_sdk/trtc_cloud_video_view.dart';
import 'package:tencent_trtc_cloud/trtc_cloud_def.dart';

import '../controller/video_calling_controller.dart';
import 'CallParams.dart';

class TimeText extends StatefulWidget {
  TimeText({
    Key? key,
    required this.startTime,
  }) : super(key: key);
  final startTime;
 

  @override
  _TimeText createState() => _TimeText();
}

class _TimeText extends State<TimeText> {
  late Timer _timer;
  late Duration _duration;


  @override
  void initState() {
    super.initState();
    _duration = DateTime.now().difference(widget.startTime); // 计算持续时间
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
        setState(() {
          _duration = DateTime.now().difference(
            widget.startTime,
          ); // 更新持续时间，每秒更新一次
        });
    });
  }

  @override
  void dispose() {
    _timer.cancel(); // 取消计时器以避免内存泄漏
    super.dispose();
  }

  // 显示时间
  String showTimeText(hours, minutes, seconds) {
    final calminutes = hours * 60 + minutes;
    final mText = calminutes < 10 ? '0${calminutes}' : '${calminutes}';
    final sText = seconds < 10 ? '0${seconds}' : '${seconds}';
    return '${mText}:${sText}';
  }


  @override
  Widget build(BuildContext context) {
    return Text(
                showTimeText(
                  _duration.inHours,
                  _duration.inMinutes % 60,
                  _duration.inSeconds % 60,
                ),
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 14,
                  color: Color((0xFF333333)),
                  fontWeight: FontWeight.w700,
                ),
              );
  }
}
